package com.eedi.framework.tenant.controller.sys;

import com.eedi.framework.common.pojo.CommonResult;
import com.eedi.framework.tenant.controller.sys.vo.setup.SysSetupBottomReq;
import com.eedi.framework.tenant.controller.sys.vo.setup.SysSetupBottomResp;
import com.eedi.framework.tenant.controller.sys.vo.setup.SysSetupBottomUpReq;
import com.eedi.framework.tenant.service.SysSetupBottomService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import java.util.List;
import static com.eedi.framework.common.pojo.CommonResult.success;

/**
 * 系统界面 - 底部设置
 *
 * @author zybourn
 */
@Tag(name = "系统界面 - 底部设置")
@RestController
@RequestMapping("/setup/bottom")
public class SysSetupBottomController {
    @Resource
    SysSetupBottomService sysSetupBottomService;

    @PostMapping("/create")
    @Operation(summary = "设置当前租户的系统底部设置")
    @PreAuthorize("@sys.hasPermission('sys:setup:bottom-create')")
    public CommonResult<Void> create(@RequestBody SysSetupBottomReq req) {
        sysSetupBottomService.create(req);
        return success(null);
    }

    @PostMapping("/update")
    @Operation(summary = "更新当前租户的系统底部设置")
    @PreAuthorize("@sys.hasPermission('sys:setup:bottom-update')")
    public CommonResult<Void> update(@RequestBody SysSetupBottomUpReq req) {
        sysSetupBottomService.update(req);
        return success(null);
    }

    @PutMapping("/enable")
    @Operation(summary = "启用底部设置")
    @Parameter(name = "sysSetupBottomId", description = "设置项ID", required = true, example = "1234556")
    @PreAuthorize("@sys.hasPermission('sys:setup:bottom-enable')")
    public CommonResult<Void> enable(@RequestParam("sysSetupBottomId") String sysSetupBottomId) {
        sysSetupBottomService.enable(sysSetupBottomId);
        return success(null);
    }

    @PutMapping("/disable")
    @Operation(summary = "禁用底部设置")
    @Parameter(name = "sysSetupBottomId", description = "设置项ID", required = true, example = "1234556")
    @PreAuthorize("@sys.hasPermission('sys:setup:bottom-disable')")
    public CommonResult<Void> disable(@RequestParam("sysSetupBottomId") String sysSetupBottomId) {
        sysSetupBottomService.disable(sysSetupBottomId);
        return success(null);
    }

    @PutMapping("/get-list")
    @Operation(summary = "获取设置列表")
    @PermitAll
    public CommonResult<List<SysSetupBottomResp>> getList() {
        return success(sysSetupBottomService.getList());
    }
}
